<!--  -->
<template>
<div class=''>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
        <el-row :gutter="20">
             <el-col :span="7">  <el-input placeholder="请输入内容" clearable v-model="params.findKeyWord">
                 <el-button icon="el-icon-search"  slot="append" @click="searchGoods()"></el-button></el-input></el-col>
                <el-col :span="4"
          ><el-button type="primary" @click="addGoods()">添加商品</el-button></el-col>
        </el-row>
       <el-table
      :data="goodsList"
      style="width: 100%"
      border stripe>
      <el-table-column
        prop="goodsname"
        label="商品名称"
        width="700">
      </el-table-column>
      <el-table-column
        prop="price"
        label="商品价格"
        width="100">
      </el-table-column>
      <el-table-column
        prop="height"
        label="商品重量">
      </el-table-column>
         <el-table-column
        prop="time"
        label="创建时间">
      </el-table-column>
            <el-table-column
        label="操作">
        <template slot-scope="scope">
            <el-button icon="el-icon-edit" size="mini" type="primary"></el-button>
             <el-button icon="el-icon-delete" size="mini" type="danger" @click="deleteData(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="params.pageNum"
      :page-sizes="[1, 2, 3, 4,5,6,7,8]"
      :page-size="params.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
      hide-on-single-page
     >
    </el-pagination>






    </el-card>


</div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
//import引入的组件需要注入到对象中才能使用
components: {},
data() {
//这里存放数据
return {
  goodsList:[],
  params:{
      pageSize:6,
      pageNum:1,
      findKeyWord:''
  },
  count:0
};
},
//监听属性 类似于data概念
computed: {},
//监控data中的数据变化
watch: {},
//方法集合
methods: {
  async requestGoodsList(){
    let {data} = await this.$http.get("/goodsList",{params:this.params})
    console.log(data);
    
    if(data.err==0){
      this.$message.success(data.msg)
      this.goodsList = data.data
      this.count = data.count
    }else{
        this.$message.warning(data.msg)
    }
  },
  searchGoods(){
      this.requestGoodsList()
  },
  handleSizeChange(e){
    this.params.pageSize =e
     this.requestGoodsList()
  },
  handleCurrentChange(e){
    this.params.pageNum = e
     this.requestGoodsList()
    
  },
  deleteData(e){
     this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
         let {data} =await this.$http.post("/goodsList/delete",{id:e.id})
         if(data.err==0){
           this.$message.success(data.msg)
           this.requestGoodsList()
         }
            
 }).catch(() => {
              this.$message.success("删除失败,内部错误")
        });
  },
  addGoods(){
     this.$router.push('/addgoods')  
  }
},
//生命周期 - 创建完成（可以访问当前this实例）
created() {
  this.requestGoodsList()
},
//生命周期 - 挂载完成（可以访问DOM元素）
mounted() {

},
beforeCreate() {}, //生命周期 - 创建之前
beforeMount() {}, //生命周期 - 挂载之前
beforeUpdate() {}, //生命周期 - 更新之前
updated() {}, //生命周期 - 更新之后
beforeDestroy() {}, //生命周期 - 销毁之前
destroyed() {}, //生命周期 - 销毁完成
activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
deactivated() {}
}
</script>
<style  scoped>
.el-table{
    margin: 10px 0 10px 0;
}
</style>